package com.turing.post.webservice.impl;

import java.util.Hashtable;
import java.util.List;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.turing.post.datatranferpmbs.util.PMBSMchTradDetailBusiness;
import com.turing.post.util.PCPSApplicationException;

public class MrchHisTradDetailTest implements Runnable {

	private Integer number;

	public MrchHisTradDetailTest() {
	}

	public MrchHisTradDetailTest(Integer number) {
		this.number = number;
	}

	public static void main(String[] args) throws InterruptedException {
		for (int i = 0; i <= 12; i++) {
			MrchHisTradDetailTest test = new MrchHisTradDetailTest(i);
			Thread thread = new Thread(test);
			thread.start();
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	public void run() {
		// 用户登录成功信息检测
		Context ctx = null;
		// 根据客户端传来的名字查找相应的实现EJB
		PMBSMchTradDetailBusiness dao = null;
		String name = "datatranferpmbs.impl.PMBSMchTradDetailBusinessImpl"
				+ "#" + PMBSMchTradDetailBusiness.class.getName();

		Hashtable env = new Hashtable();
		env.put(InitialContext.INITIAL_CONTEXT_FACTORY,
				"weblogic.jndi.WLInitialContextFactory");
		env.put(InitialContext.PROVIDER_URL, "t3://127.0.0.1:7001");

		try {
			ctx = new InitialContext(env);
		} catch (NamingException e1) {
			e1.printStackTrace();
		}

		try {
			dao = (PMBSMchTradDetailBusiness) ctx.lookup(name);
		} catch (NamingException e) {
			e.printStackTrace();
		}
		List<Object[]> objList = dao.getMchTradDetailTranDateList();
		Object[] objs = null;
		// long all = System.currentTimeMillis();
		int a = number * 100;
		for (int i = a; i <= a + 99; i++) {
			objs = objList.get(i);
			// System.out.println("Start 线程" + number + " 条数：" + objs[1]);
			// long l = System.currentTimeMillis();
			objs = objList.get(i);
			try {
				dao.transferPMBSMchTradDetail("", objs[0].toString());
			} catch (PCPSApplicationException e) {
				e.printStackTrace();
			}
			// System.out.println("End 线程" + number + "耗时："
			// + (System.currentTimeMillis() - l) / 1000);
		}
		// System.out.println("线程" + number + "总耗时："
		// + (System.currentTimeMillis() - all) / 1000);
	}
}
